﻿using RaceHFTools.BluetoothLE.Bean.Module;
using System;
using System.IO;
using Xamarin.Forms;

namespace RaceHFTools.Utils
{
    public static class File
    {
        public static string Root { get; private set; } = string.Empty;

        private static string LogRoot;

        public static string Log
        {
            get
            {
                DateTime now = DateTime.Now;
                string logname = $"{now.Year}-{now.Month}-{now.Day}-{now.Hour}-{now.Minute}-{now.Second}.log";
                return Path.Combine(LogRoot, logname);
            }
        }

        public static string Firmware
        {
            get => Path.Combine(Root, "fw.bin");
        }

        public static string Bootloader
        {
            get => Path.Combine(Root, "bl.bin");
        }

        public static void SetRoot(string root)
        {
            Root = root;
            LogRoot = Path.Combine(Root, "Log");

            if (!Directory.Exists(Root))
                Directory.CreateDirectory(Root);

            if (!Directory.Exists(LogRoot))
                Directory.CreateDirectory(LogRoot);
        }
    }
}
